package ${packageName};

import java.util.*;
import lombok.Data;

<#if imports??>
<#list imports as import>
import ${import};
</#list>
</#if>

/**
 * ${className}
 * 自动生成的实体类
 */
@Data
public class ${className} {
    <#list fields as field>
    /**
     * ${field.name}
     */
    private ${field.type} ${field.name};
    </#list>

    public ${className}() {
    }

    public ${className}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
        <#list fields as field>
        this.${field.name} = ${field.name};
        </#list>
    }

    <#-- 为集合类型字段添加添加/删除方法 -->
    <#list fields as field>
    <#if field.type?starts_with("List")>
    public void add${field.capitalizedName}(${field.type?replace("List<", "")?replace(">", "")} item) {
        if (this.${field.name} == null) {
            this.${field.name} = new ArrayList<>();
        }
        this.${field.name}.add(item);
    }

    public void remove${field.capitalizedName}(${field.type?replace("List<", "")?replace(">", "")} item) {
        if (this.${field.name} != null) {
            this.${field.name}.remove(item);
        }
    }
    </#if>
    </#list>
}
